<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">


<html>
<head>
    <meta charset="utf-8"/>
    <title>文章编辑页</title>
    <meta name="keywords" content="设置关键词..."/>
    <meta name="description" content="设置描述..."/>
    <meta name="author" content="DeathGhost"/>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <link rel="icon" href="/content/icon/favicon.ico" type="image/x-icon">
    <link rel="stylesheet" type="text/css" href="css/style.css"/>
    <script src="/js/jquery.js"></script>
    <script src="/js/public.js"></script>
    <script src="/js/jquery-form.js"></script>

    <link rel="stylesheet" type="text/css" href="/css/style.css"/>
    <script charset="utf-8" src="/editor/kindeditor.js"></script>
    <script charset="utf-8" src="/editor/lang/zh-CN.js"></script>
    <script language="javascript" type="text/javascript" src="/js/My97DatePicker/WdatePicker.js"></script>
    <script>
        KindEditor.ready(function(K) {
            window.editor = K.create('#editor_id', {
                uploadJson : '/editor/jsp/upload_json.jsp',
                fileManagerJson : '/editor/jsp/file_manager_json.jsp',
                allowFileManager : true
            });
        });
        
        function vilidate(title,img) {
            if(title == null  || title == ""){
                alert(title+img);
                $("#error_dialog").css('display','block');
                $("#mask").css('display','block');
                $("#error_info").text("未添加标题");
                return false;
            }else if(img == null  || img == ""){
                alert(title+img);
                $("#error_dialog").css('display','block');
                $("#mask").css('display','block');
                $("#error_info").text("未添加图片");
                return false;
            }
            return true;
        }

        function submitForm() {
            var title = $('#title').val();
            var img = $('#img1_path').val();
            if(!vilidate(title,img)){

                alert(title+img);
                return false;
            }
            editor.sync();
            // 创建Form
            var form = $('<form action="/admin/addArticle" method="post" target="_self"></form>');
            $(document.body).append(form);

            form.append($('<input type="text" name="title" />').attr('value', title));
            form.append($('<input type="text" name="content" />').attr('value', $('#editor_id').val()));
            form.append($('<input type="text" name="endDate" />').attr('value', $('#end_date').val()));
            form.append($('<input type="text" name="wechatName" />').attr('value', $('#wechat_name').val()));
            form.append($('<input type="text" name="wechatUrl" />').attr('value', $('#wechat_url').val()));
            if($('#weigh_number').val() == ""){
                form.append($('<input type="text" name="weighNumber" />').attr('value', 0));
            }else{
                form.append($('<input type="text" name="weighNumber" />').attr('value', $('#weigh_number').val()));
            }
            form.append($('<input type="text" name="img" />').attr('value', img));
            form.append($('<input type="text" name="type" />').attr('value', $("input[name='type']:checked").val()));
            // 提交表单
            form.submit();
            // 注意return false取消链接的默认动作
            return false;
        }

        function upload() {
            var form = $('<form target="_self" method="post"  action="/upload/uploadFile" enctype="multipart/form-data"></form>');
            $(document.body).append(form);
            form.append($('#fileName'));
            form.ajaxSubmit({
                type: "POST",//提交类型
                dataType: "json",//返回结果格式
                url: "/upload/uploadFile",//请求地址
                data: { "action": "TemporaryImage"},//请求数据
                success: function (data) {//请求成功后的函数
                    $("#img1").css('display','block');
                    $("#img1").attr("src","http://or5mz5dbj.bkt.clouddn.com/" + data.data);
                    $('#img1_path').attr("value",data.data);
                },
                error: function (data) {
                    alert(data.msg); },//请求失败的函数
                async: true
            });
        }
    </script>
</head>
<body>
<c:import url="menu.jsp"></c:import>
<main class="main-cont content mCustomScrollbar">
    <!--开始::内容-->
    <div class="page-wrap">
        <section class="page-hd">
            <header>
                <h2 class="title"><i class="icon-home"></i>文章编辑页</h2>
                <p class="title-description">
                    页面说明
                </p>
            </header>
            <hr>
        </section>

        <div class="content-wrap">
            <header class="top-hd">
                <div class="hd-lt">
                    <a class="icon-reorder"></a>
                </div>
                <div class="hd-rt">
                    <ul>
                        <li>
                            <a href="#" target="_blank"><i class="icon-home"></i>前台访问</a>
                        </li>
                        <li>
                            <a><i class="icon-random"></i>清除缓存</a>
                        </li>
                        <li>
                            <a><i class="icon-user"></i>管理员:<em>DeathGhost</em></a>
                        </li>
                        <li>
                            <a><i class="icon-bell-alt"></i>系统消息</a>
                        </li>
                        <li>
                            <a href="javascript:void(0)" id="JsSignOut"><i class="icon-signout"></i>安全退出</a>
                        </li>
                    </ul>
                </div>
            </header>
            <main class="main-cont content mCustomScrollbar">
                <div class="page-wrap">
                    <!--开始::内容-->
                    <section class="page-hd">
                        <header>
                            <h2 class="title">文章编辑页</h2>
                            <p class="title-description">
                                文章编辑
                            </p>
                        </header>
                        <hr>
                    </section>
                    <div class="form-group-col-2">
                        <div class="form-label"><font style="color: red">*</font>文章标题：</div>
                        <div class="form-cont">
                            <input type="text" id="title" placeholder="标题" class="form-control form-boxed">
                        </div>
                    </div>
                    <div class="form-group-col-2">
                        <div class="form-label"><font style="color: red">*</font>文章图片：</div>
                        <div class="form-cont">
                            <input name="fileName" id="fileName" type="file" class="text1" size="40" maxlength="40" onchange="upload()">
                            <img id="img1" width="80px" height="80px" style="display: none"/>
                            <input id="img1_path"  type="hidden">
                        </div>
                    </div>
                    <div class="form-group-col-2">
                        <div class="form-label">结束日期：</div>
                        <div class="form-cont">
                            <input id="end_date" class="Wdate" onFocus="WdatePicker({lang:'zh-cn'})" />
                        </div>
                    </div>
                    <div class="form-group-col-2">
                        <div class="form-label">公众号名称：</div>
                        <div class="form-cont">
                            <input type="text" id="wechat_name" placeholder="公众号名称" class="form-control form-boxed">
                        </div>
                    </div>
                    <div class="form-group-col-2">
                        <div class="form-label">公众号URL：</div>
                        <div class="form-cont">
                            <input type="text" id="wechat_url" placeholder="公众号URL" class="form-control form-boxed">
                        </div>
                    </div>
                    <div class="form-group-col-2">
                        <div class="form-label">排序权重：</div>
                        <div class="form-cont">
                            <input type="text" onkeyup="this.value=this.value.replace(/[^0-9]/g,'')" onafterpaste="this.value=this.value.replace(/[^0-9]/g,'')" id="weigh_number" placeholder="排序权重" class="form-control form-boxed">
                        </div>
                    </div>
                    <div class="form-group-col-2">
                        <div class="form-label"><font style="color: red">*</font>分类：</div>
                        <div class="form-cont">
                            <label class="radio">
                                <input type="radio" name="type" value="1" checked="checked"/>
                                <span>热点</span>
                            </label>
                            <label class="radio">
                                <input type="radio" name="type"  value="2"/>
                                <span>娱乐</span>
                            </label>
                            <label class="radio">
                                <input type="radio" name="type" value="3"/>
                                <span>养生</span>
                            </label>
                            <label class="radio">
                                <input type="radio" name="type" value="4"/>
                                <span>搞笑</span>
                            </label>
                            <label class="radio">
                                <input type="radio" name="type" value="5"/>
                                <span>奇闻</span>
                            </label>
                            <label class="radio">
                                <input type="radio" name="type" value="6"/>
                                <span>励志</span>
                            </label>
                            <label class="radio">
                                <input type="radio" name="type" value="7"/>
                                <span>科技</span>
                            </label>
                            <label class="radio">
                                <input type="radio" name="type" value="8"/>
                                <span>生活</span>
                            </label>
                            <label class="radio">
                                <input type="radio" name="type" value="9"/>
                                <span>财经</span>
                            </label>
                            <label class="radio">
                                <input type="radio" name="type" value="10"/>
                                <span>汽车</span>
                            </label>
                            <label class="radio">
                                <input type="radio" name="type" value="11"/>
                                <span>情感</span>
                            </label>
                            <label class="radio">
                                <input type="radio" name="type" value="12"/>
                                <span>星座</span>
                            </label>
                            <label class="radio">
                                <input type="radio" name="type" value="13"/>
                                <span>美食</span>
                            </label>
                            <label class="radio">
                                <input type="radio" name="type" value="14"/>
                                <span>时尚</span>
                            </label>
                            <label class="radio">
                                <input type="radio" name="type" value="15"/>
                                <span>旅游</span>
                            </label>
                            <label class="radio">
                                <input type="radio" name="type" value="16"/>
                                <span>育儿</span>
                            </label>
                            <label class="radio">
                                <input type="radio" name="type" value="17"/>
                                <span>体育</span>
                            </label>
                            <label class="radio">
                                <input type="radio" name="type" value="18"/>
                                <span>军事</span>
                            </label>
                            <label class="radio">
                                <input type="radio" name="type" value="19"/>
                                <span>历史</span>
                            </label>
                            <label class="radio">
                                <input type="radio" name="type" value="20"/>
                                <span>三农</span>
                            </label>
                            <label class="radio">
                                <input type="radio" name="type" value="21"/>
                                <span>故事</span>
                            </label>
                            <label class="radio">
                                <input type="radio" name="type" value="22"/>
                                <span>收藏</span>
                            </label>
                        </div>
                    </div>
                    <div class="form-group-col-2">
                        <div class="form-label"><font style="color: red">*</font>摘要：</div>
                        <div class="form-cont">
                            <textarea id="editor_id" style="width:700px;height:300px;">请输入内容</textarea>
                        </div>
                    </div>
                    <div class="form-group-col-2">
                        <div class="form-label"></div>
                        <div class="form-cont">
                            <input type="submit" class="btn btn-primary" value="提交表单" onclick="submitForm()"/>
                        </div>
                    </div>
                </div>
            </main>
        </div>
    </div>



    </div>

</main>
<div class="mask"  id="mask"></div>
<div class="dialog Jmsg" id="error_dialog">
    <div class="dialog-hd">
        <strong class="lt-title">ERROR</strong>
        <a class="rt-operate icon-remove Jmsg" title="关闭"></a>
    </div>
    <div class="dialog-bd">
        <!--start::-->
        <p id="error_info"></p>
        <!--end::-->
    </div>
    <div class="dialog-ft">
        <button class="btn btn-info JyesBtn">确认</button>
        <button class="btn btn-secondary JnoBtn">关闭</button>
    </div>
</div>
<c:import url="footer.jsp"/>
